
cc.Class({
    extends: cc.Component,

    properties: {
        text: {
            default: '',
            notify() {
                this._updateContent();
            }
        },
        arrow: cc.Node,
        bg: cc.Node,
        rolenode: cc.Node,
    },

    start() {

        this.node.getChildByName('bg').active = true
        this.scheduldArrow()
        this.bg.scale = window.zoom_scale
        this.rolenode.scale = window.zoom_scale
        this.label.scale = window.zoom_scale
        this.node.on(cc.Node.EventType.TOUCH_START, () => {
            this.node._touchListener.setSwallowTouches(false);
            //隐藏文本提示
            if (this.node.active) {
                this.node.active = false;
                this.node.emit('click');
                return;
            }
        });
    },

    _updateContent() {
        this.node.active = true;
        if (!this.label) {
            this.label = this.node.getComponentInChildren(cc.Label);
        }
        this.label.string = this.text;
    },

    scheduldArrow() {
        this.schedule(this.arrowServer, 2)
    },

    arrowServer() {
        this.arrowTween = cc.tween(this.arrow)
            .to(0.5, { y: -160 })
            .to(0.5, { y: -150 })
            .start()
    },

    onDestroy() {
        this.unschedule(this.arrowServer)
        if (this.arrowTween) {
            this.arrowTween.stop()
            this.arrowTween = null
        }
    }
});
